﻿using System.Windows.Forms;
using System;


namespace FlashUnity
{

  public partial class Unity3d : UserControl
  {
    private AxHost.State NewState;
    private AxUnityWebPlayerAXLib.AxUnityWebPlayer unityPlayer;
    public FlashUnity.Player.PlayerState playState { get; set; }
    public FlashUnity.Player Player;
    public  new event EventHandler GotFocus;
    public new event EventHandler LostFocus;

    public Unity3d()
    {

    }

    internal void Play(string Url)
    {
      CreateUnityState(Url);
      Initialize();
    }

    private void CreateUnityState(string url)
    {
      System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Unity3d));
      unityPlayer = new AxUnityWebPlayerAXLib.AxUnityWebPlayer();
      ((System.ComponentModel.ISupportInitialize)(unityPlayer)).BeginInit();
      unityPlayer.Name = "UnityPlayer1";
      unityPlayer.Dock = DockStyle.Fill;
      unityPlayer.OcxState = ((System.Windows.Forms.AxHost.State)(resources.GetObject("UnityPlayer1.OcxState")));
      Controls.Add(unityPlayer);
      ((System.ComponentModel.ISupportInitialize)(unityPlayer)).EndInit();
      unityPlayer.src = url;
      NewState = unityPlayer.OcxState;
      unityPlayer.Dispose();
    }

    private void Initialize()
    {
      this.UnityWebPlayer = new AxUnityWebPlayerAXLib.AxUnityWebPlayer();
      ((System.ComponentModel.ISupportInitialize)(this.UnityWebPlayer)).BeginInit();
      this.SuspendLayout();
      // 
      // UnityWebPlayer
      // 
      this.UnityWebPlayer.Dock = System.Windows.Forms.DockStyle.Fill;
      this.UnityWebPlayer.Enabled = true;
      this.UnityWebPlayer.Location = new System.Drawing.Point(0, 0);
      this.UnityWebPlayer.Margin = new System.Windows.Forms.Padding(0);
      this.UnityWebPlayer.Name = "UnityWebPlayer";
      this.UnityWebPlayer.OcxState = NewState;
      this.UnityWebPlayer.GotFocus += UnityWebPlayer_GotFocus;
      this.UnityWebPlayer.LostFocus += UnityWebPlayer_LostFocus;
      this.UnityWebPlayer.Size = new System.Drawing.Size(864, 507);
      this.UnityWebPlayer.TabIndex = 0;
      // 
      // Unity3dPlayer
      // 
      this.Controls.Add(this.UnityWebPlayer);
      this.Margin = new System.Windows.Forms.Padding(0);
      this.Name = "Unity3dPlayer";
      this.Size = new System.Drawing.Size(864, 507);
      ((System.ComponentModel.ISupportInitialize)(this.UnityWebPlayer)).EndInit();
      this.ResumeLayout(false);
    }

    void UnityWebPlayer_LostFocus(object sender, EventArgs e)
    {
      if (this.LostFocus != null) this.LostFocus(this, new EventArgs());
    }

    void UnityWebPlayer_GotFocus(object sender, System.EventArgs e)
    {
      if (this.GotFocus != null) this.GotFocus(this, new EventArgs());
    }

    private AxUnityWebPlayerAXLib.AxUnityWebPlayer UnityWebPlayer;
  }
}
